﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Combinatorics.Collections;
using RuleOfReady.Core.DomainModels.Tiles;
using RuleOfReady.Core.DomainModels.Sets;
using RuleOfReady.Core.Engines;

namespace RuleOfReady.SequenceListing
{
    class SequenceListing
    {
        static void Main(string[] args)
        {
            TileEngine engine = new TileEngine();

            IEnumerable<IEnumerable<MahjongTile>> dotSequences = engine.SequencesBySuit[MahjongSuitType.Dot];
            Console.WriteLine("Sequences of dot tiles:");
            Console.WriteLine();
            Console.WriteLine("Completed -->  Partial");
            Console.WriteLine("--------- -->  ---------");
            foreach (IEnumerable<MahjongTile> seq in dotSequences)
            {
                List<MahjongTile> seqList = seq.ToList();
                IEnumerable<IEnumerable<MahjongTile>> partialSeq = 
                    new Combinations<MahjongTile>(seqList, 2, GenerateOption.WithoutRepetition);
                StringBuilder sb = new StringBuilder();
                foreach (MahjongTile tile in seq)
                {
                    sb.Append(tile).Append(" ");
                }
                sb.Append(" -->  ");
                foreach (IEnumerable<MahjongTile> partial in partialSeq)
                {
                    foreach (MahjongTile tile in partial)
                    {
                        sb.Append(tile).Append(" ");
                    }
                    sb.Remove(sb.Length - 1, 1);
                    sb.Append(", ");
                }
                string seqString = sb.ToString().TrimEnd(',',' ');
                Console.WriteLine(seqString);

            }
            Console.WriteLine();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }
}
